```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Netty线程模型源码分析 | 技术小馆</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8f9fa;
            color: #333;
            line-height: 1.6;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background-color: #2d3748;
            border-radius: 0.5rem;
            position: relative;
        }
        .code-header {
            background-color: #1a202c;
            border-top-left-radius: 0.5rem;
            border-top-right-radius: 0.5rem;
            padding: 0.5rem 1rem;
            color: #e2e8f0;
            font-size: 0.875rem;
            display: flex;
            justify-content: space-between;
        }
        .copy-btn {
            color: #a0aec0;
            cursor: pointer;
            transition: all 0.2s;
        }
        .copy-btn:hover {
            color: #fff;
        }
        .code-content {
            padding: 1rem;
            overflow-x: auto;
            color: #e2e8f0;
            font-family: 'Courier New', Courier, monospace;
            font-size: 0.875rem;
            line-height: 1.5;
        }
        .hover-scale {
            transition: transform 0.3s ease;
        }
        .hover-scale:hover {
            transform: translateY(-3px);
        }
        .section-divider {
            height: 1px;
            background: linear-gradient(90deg, rgba(200,200,200,0) 0%, rgba(160,174,192,0.5) 50%, rgba(200,200,200,0) 100%);
            margin: 3rem 0;
        }
        .highlight-box {
            border-left: 4px solid #6e8efb;
            background-color: rgba(110, 142, 251, 0.05);
            padding: 1.5rem;
            border-radius: 0 0.5rem 0.5rem 0;
        }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6 md:py-32">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6 font-serif">Netty线程模型源码分析</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8">深入解析高性能网络框架的核心设计原理</p>
            <div class="flex justify-center space-x-4">
                <a href="#content" class="bg-white text-indigo-600 hover:bg-indigo-50 px-8 py-3 rounded-full font-medium transition duration-300 shadow-md hover:shadow-lg">
                    <i class="fas fa-book-open mr-2"></i>开始阅读
                </a>
                <a href="#diagram" class="bg-indigo-700 hover:bg-indigo-800 text-white px-8 py-3 rounded-full font-medium transition duration-300 shadow-md hover:shadow-lg">
                    <i class="fas fa-project-diagram mr-2"></i>架构图解
                </a>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-4xl mx-auto px-6 py-12" id="content">
        <div class="bg-white rounded-xl shadow-md overflow-hidden mb-10 p-8">
            <p class="text-lg text-gray-700 mb-6">
                Netty 的线程模型是其高效处理高并发网络请求的关键设计之一。在 Netty 中，线程的管理和调度是基于事件驱动模型的，并且有着精细的控制与优化，以确保可以处理大量并发请求而不会造成线程瓶颈。
            </p>
            
            <!-- Section 1 -->
            <div class="mb-12">
                <div class="flex items-center mb-6">
                    <div class="bg-indigo-100 text-indigo-800 rounded-full w-10 h-10 flex items-center justify-center font-bold mr-4">1</div>
                    <h2 class="text-2xl font-bold text-gray-800">线程模型的概述</h2>
                </div>
                <div class="ml-14">
                    <p class="mb-4">Netty 的线程模型是基于事件驱动模型和线程池的。主要包括三个核心部分：<code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code>、<code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoopGroup</code> 和 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">Channel</code>。通过这些组件，Netty 能够高效地调度和管理多个线程来处理并发的 I/O 事件。</p>
                    
                    <div class="bg-gray-50 p-6 rounded-lg mb-6">
                        <h3 class="font-bold text-lg text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-cog mr-2 text-indigo-500"></i>核心组件
                        </h3>
                        <ul class="space-y-2">
                            <li class="flex items-start">
                                <div class="bg-indigo-500 text-white rounded-full w-5 h-5 flex items-center justify-center mt-1 mr-3 text-xs font-bold">+</div>
                                <div><code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code>: 负责事件循环的处理，每个线程中运行一个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 实例。</div>
                            </li>
                            <li class="flex items-start">
                                <div class="bg-indigo-500 text-white rounded-full w-5 h-5 flex items-center justify-center mt-1 mr-3 text-xs font-bold">+</div>
                                <div><code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoopGroup</code>: 是由多个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 组成的线程池，用于管理和分配事件处理线程。</div>
                            </li>
                            <li class="flex items-start">
                                <div class="bg-indigo-500 text-white rounded-full w-5 h-5 flex items-center justify-center mt-1 mr-3 text-xs font-bold">+</div>
                                <div><code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Channel</code>: 每个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Channel</code> 都会绑定到一个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 上，事件处理通过 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">ChannelPipeline</code> 顺序执行。</div>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>

            <div class="section-divider"></div>

            <!-- Section 2 -->
            <div class="mb-12" id="eventloop">
                <div class="flex items-center mb-6">
                    <div class="bg-indigo-100 text-indigo-800 rounded-full w-10 h-10 flex items-center justify-center font-bold mr-4">2</div>
                    <h2 class="text-2xl font-bold text-gray-800">EventLoop 的实现与执行流程</h2>
                </div>
                <div class="ml-14">
                    <p class="mb-4"><code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code> 是 Netty 线程模型的核心组件，它负责接收和处理网络 I/O 事件。每个 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code> 实际上是一个线程，用于执行 I/O 任务。</p>
                    
                    <div class="code-block mb-6 hover-scale">
                        <div class="code-header">
                            <span>EventLoop.java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <div class="code-content">
                            <pre>public interface EventLoop extends EventExecutor {
    void run();  // 启动事件循环，监听并处理 I/O 事件
}</pre>
                        </div>
                    </div>

                    <div class="highlight-box mb-6">
                        <h3 class="font-bold text-lg text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-code-branch mr-2 text-indigo-500"></i>执行流程
                        </h3>
                        <ol class="list-decimal pl-5 space-y-2">
                            <li><strong>事件循环启动</strong>：<code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 的生命周期由 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">run()</code> 方法控制。这个方法会不断轮询事件队列中的事件，并根据事件类型分发到合适的 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">ChannelHandler</code>。</li>
                            <li><strong>事件的分发</strong>：<code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 会等待某个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Channel</code> 上的事件（如连接请求、数据可读等），当事件到达时，它会将事件传递到相应的 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">ChannelPipeline</code> 中进行处理。</li>
                        </ol>
                    </div>

                    <div class="code-block hover-scale">
                        <div class="code-header">
                            <span>核心执行代码</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <div class="code-content">
                            <pre>// 核心执行代码
@Override
public void run() {
    while (!isShutDown) {
        try {
            // 获取下一个事件
            processNextEvent();
        } catch (Exception e) {
            // 异常处理
            handleException(e);
        }
    }
}</pre>
                        </div>
                    </div>
                </div>
            </div>

            <div class="section-divider"></div>

            <!-- Section 3 -->
            <div class="mb-12">
                <div class="flex items-center mb-6">
                    <div class="bg-indigo-100 text-indigo-800 rounded-full w-10 h-10 flex items-center justify-center font-bold mr-4">3</div>
                    <2 class="text-2xl font-bold text-gray-800">EventLoopGroup 的管理与线程分配</h2>
                </div>
                <div class="ml-14">
                    <p class="mb-4"><code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoopGroup</code> 是由多个 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code> 实例组成的线程池，负责管理和调度 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code>。<code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoopGroup</code> 可以分配不同的线程处理不同的任务，从而提高并发性能。</p>
                    
                    <h3 class="font-bold text-lg text-gray-800 mb-3 mt-6 flex items-center">
                        <i class="fas fa-file-code mr-2 text-indigo-500"></i>EventLoopGroup 核心源码：
                    </h3>
                    <div class="code-block mb-6 hover-scale">
                        <div class="code-header">
                            <span>EventLoopGroup.java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <div class="code-content">
                            <pre>public interface EventLoopGroup extends EventExecutorGroup {
    EventLoop next(); // 获取下一个 EventLoop 实例
}</pre>
                        </div>
                    </div>

                    <div class="highlight-box mb-6">
                        <h3 class="font-bold text-lg text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-code-branch mr-2 text-indigo-500"></i>执行流程
                        </h3>
                        <ol class="list-decimal pl-5 space-y-2">
                            <li><strong>线程分配</strong>：<code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoopGroup</code> 会根据负载情况为每个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Channel</code> 分配一个合适的 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code>。它通常会使用 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">next()</code> 方法轮询选择一个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code>，从而避免单个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 线程的过载。</li>
                            <li><strong>并发处理</strong>：通过多个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 并行处理不同的 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Channel</code> 事件，<code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoopGroup</code> 提高了系统的并发性能，并且避免了线程间的资源竞争。</li>
                        </ol>
                    </div>

                    <div class="code-block hover-scale">
                        <div class="code-header">
                            <span>EventLoopGroup 轮询选择一个 EventLoop</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <div class="code-content">
                            <pre>// EventLoopGroup 轮询选择一个 EventLoop
@Override
public EventLoop next() {
    // 轮询或者选择一个空闲的 EventLoop
    return (EventLoop) nextThread();
}</pre>
                        </div>
                    </div>
                </div>
            </div>

            <div class="section-divider"></div>

            <!-- Section 4 -->
            <div class="mb-12">
                <div class="flex items-center mb-6">
                    <div class="bg-indigo-100 text-indigo-800 rounded-full w-10 h-10 flex items-center justify-center font-bold mr-4">4</div>
                    <h2 class="text-2xl font-bold text-gray-800">线程的模型与优化设计</h2>
                </div>
                <div class="ml-14">
                    <p class="mb-4">Netty 的线程模型采用了线程池 + 事件驱动的方式来提升并发处理能力。在高并发场景下，Netty 的线程模型可以高效地处理大量并发请求。它的设计优化了线程的使用，避免了线程创建与销毁的频繁开销。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mt-6">
                        <div class="bg-indigo-50 p-6 rounded-lg hover-scale">
                            <div class="text-indigo-600 text-3xl mb-3">
                                <i class="fas fa-bolt"></i>
                            </div>
                            <h3 class="font-bold text-lg text-gray-800 mb-2">事件驱动</h3>
                            <p class="text-gray-700">通过事件驱动的方式，线程仅在有事件时才被唤醒，避免了线程的无效等待。</p>
                        </div>
                        <div class="bg-indigo-50 p-6 rounded-lg hover-scale">
                            <div class="text-indigo-600 text-3xl mb-3">
                                <i class="fas fa-recycle"></i>
                            </div>
                            <h3 class="font-bold text-lg text-gray-800 mb-2">线程复用</h3>
                            <p class="text-gray-700"><code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 线程池中的线程是可以复用的，不需要每次事件处理都创建新线程，这样减少了线程切换和创建销毁的成本。</p>
                        </div>
                        <div class="bg-indigo-50 p-6 rounded-lg hover-scale">
                            <div class="text-indigo-600 text-3xl mb-3">
                                <i class="fas fa-project-diagram"></i>
                            </div>
                            <h3 class="font-bold text-lg text-gray-800 mb-2">I/O 线程和业务线程分离</h3>
                            <p class="text-gray-700">Netty 可以将 I/O 线程与业务线程分离，通过 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">ChannelHandler</code> 来处理业务逻辑，避免了 I/O 操作与业务逻辑处理的耦合。</p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="section-divider"></div>

            <!-- Section 5 -->
            <div class="mb-12">
                <div class="flex items-center mb-6">
                    <div class="bg-indigo-100 text-indigo-800 rounded-full w-10 h-10 flex items-center justify-center font-bold mr-4">5</div>
                    <h2 class="text-2xl font-bold text-gray-800">线程与 Channel 的绑定</h2>
                </div>
                <div class="ml-14">
                    <p class="mb-4">在 Netty 中，每个 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">Channel</code> 都会绑定到一个特定的 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code> 上。<code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code> 线程负责处理该 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">Channel</code> 上的所有 I/O 操作。通过绑定 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">Channel</code> 到 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code>，Netty 保证了每个 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">Channel</code> 的事件在同一个线程中处理，从而避免了多线程之间的竞争和同步问题。</p>
                    
                    <div class="code-block mb-6 hover-scale">
                        <div class="code-header">
                            <span>DefaultChannelPipeline.java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <div class="code-content">
                            <pre>public final class DefaultChannelPipeline extends AbstractChannelPipeline {
    private final Channel channel; // 当前 Channel

    // 初始化时绑定 EventLoop
    public DefaultChannelPipeline(Channel channel) {
        this.channel = channel;
        // 为每个 Channel 分配一个 EventLoop
        this.eventLoop = channel.eventLoop();
    }
}</pre>
                        </div>
                    </div>

                    <div class="highlight-box">
                        <h3 class="font-bold text-lg text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-code-branch mr-2 text-indigo-500"></i>执行流程
                        </h3>
                        <ol class="list-decimal pl-5 space-y-2">
                            <li><strong>绑定 EventLoop</strong>：每当一个新的 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Channel</code> 被创建时，它会通过 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 进行绑定，确保事件处理逻辑始终由同一线程执行。</li>
                            <li><strong>处理 I/O 事件</strong>：绑定后的线程会处理与 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Channel</code> 相关的所有 I/O 事件，确保所有事件都在同一个线程中按顺序执行。</li>
                        </ol>
                    </div>
                </div>
            </div>

            <div class="section-divider"></div>

            <!-- Section 6 -->
            <div class="mb-12">
                <div class="flex items-center mb-6">
                    <div class="bg-indigo-100 text-indigo-800 rounded-full w-10 h-10 flex items-center justify-center font-bold mr-4">6</div>
                    <h2 class="text-2xl font-bold text-gray-800">NioEventLoop 与 OioEventLoop 的区别</h2>
                </div>
                <div class="ml-14">
                    <p class="mb-4">Netty 支持两种 I/O 模型：NIO（非阻塞 I/O）和 OIO（阻塞 I/O）。在不同的 I/O 模型下，<code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code> 也有不同的实现。<code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">NioEventLoop</code> 用于非阻塞 I/O，<code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">OioEventLoop</code> 用于阻塞 I/O。</p>
                    
                    <div class="grid md:grid-cols-2 gap-6 mt-8">
                        <div class="code-block hover-scale">
                            <div class="code-header">
                                <span>NioEventLoop.java</span>
                                <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                            </div>
                            <div class="code-content">
                                <pre>public final class NioEventLoop extends AbstractEventLoop {
    @Override
    protected void run() {
        // NIO 模型下的事件处理代码
        while (!isShutDown) {
            // 轮询并处理非阻塞 I/O 操作
            select();
        }
    }
}</pre>
                            </div>
                        </div>
                        <div class="code-block hover-scale">
                            <div class="code-header">
                                <span>OioEventLoop.java</span>
                                <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                            </div>
                            <div class="code-content">
                                <pre>public final class OioEventLoop extends AbstractEventLoop {
    @Override
    protected void run() {
        // OIO 模型下的事件处理代码
        while (!isShutDown) {
            // 阻塞式 I/O 操作
            processBlockingIO();
        }
    }
}</pre>
                            </div>
                        </div>
                    </div>

                    <div class="highlight-box mt-6">
                        <h3 class="font-bold text-lg text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-code-branch mr-2 text-indigo-500"></i>执行流程
                        </h3>
                        <ol class="list-decimal pl-5 space-y-2">
                            <li><strong><code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">NioEventLoop</code></strong>：非阻塞 I/O 模型下，<code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">NioEventLoop</code> 会使用 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Selector</code> 来监听 I/O 事件，并在有事件发生时异步处理。</li>
                            <li><strong><code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">OioEventLoop</code></strong>：阻塞 I/O 模型下，<code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">OioEventLoop</code> 会在每个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Channel</code> 上进行阻塞的 I/O 操作，直到有数据到达或操作完成。</li>
                        </ol>
                    </div>
                </div>
            </div>

            <div class="section-divider"></div>

            <!-- Section 7 -->
            <div class="mb-12" id="diagram">
                <div class="flex items-center mb-6">
                    <div class="bg-indigo-100 text-indigo-800 rounded-full w-10 h-10 flex items-center justify-center font-bold mr-4">7</div>
                    <h2 class="text-2xl font-bold text-gray-800">EventLoop 的多线程协作</h2>
                </div>
                <div class="ml-14">
                    <p class="mb-4">为了提高性能，Netty 的 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoop</code> 可以通过多线程协作来处理 I/O 事件。例如，<code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">EventLoopGroup</code> 可以分配多个线程来并行处理不同的 <code class="bg-gray-100 px-2 py-1 rounded text-indigo-600">Channel</code>，从而提高吞吐量和并发性能。</p>
                    
                    <div class="code-block mb-6 hover-scale">
                        <div class="code-header">
                            <span>NioEventLoopGroup.java</span>
                            <span class="copy-btn"><i class="far fa-copy"></i> 复制</span>
                        </div>
                        <div class="code-content">
                            <pre>public class NioEventLoopGroup extends MultithreadEventLoopGroup {
    @Override
    protected EventLoop newChild(EventLoopGroup parent, ThreadFactory threadFactory) throws Exception {
        return new NioEventLoop(parent, threadFactory);  // 创建多个 EventLoop 实例
    }
}</pre>
                        </div>
                    </div>

                    <div class="highlight-box">
                        <h3 class="font-bold text-lg text-gray-800 mb-3 flex items-center">
                            <i class="fas fa-code-branch mr-2 text-indigo-500"></i>执行流程
                        </h3>
                        <ol class="list-decimal pl-5 space-y-2">
                            <li><strong>线程池创建</strong>：<code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoopGroup</code> 创建多个 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 实例，线程池中的每个线程会独立处理一部分 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">Channel</code> 的事件。</li>
                            <li><strong>事件分配</strong>：当新的连接请求到来时，<code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoopGroup</code> 会将其分配给一个空闲的 <code class="bg-gray-100 px-1 py-0.5 rounded text-indigo-600">EventLoop</code> 进行处理。</li>
                        </ol>
                    </div>

                    <!-- Mermaid Diagram -->
                    <div class="mt-12 bg-white p-6 rounded-xl shadow-md">
                        <h3 class="text-xl font-bold text-gray-800 mb-6 flex items-center">
                            <i class="fas fa-project-diagram mr-2 text-indigo-500"></i>Netty线程模型关系图
                        </h3>
                        <div class="mermaid">
                            graph TD
                                A[Client] -->|Request| B[EventLoopGroup]
                                B --> C[EventLoop1]
                                B --> D[EventLoop2]
                                B --> E[EventLoop3]
                                C --> F[Channel1]
                                C --> G[Channel2]
                                D --> H[Channel3]
                                E --> I[Channel4]
                                F --> J[ChannelPipeline]
                                G --> K[ChannelPipeline]
                                H --> L[ChannelPipeline]
                                I --> M[ChannelPipeline]
                                J --> N[ChannelHandler1]
                                J --> O[ChannelHandler2]
                                K --> P[ChannelHandler1]
                                K --> Q[ChannelHandler2]
                                L --> R[ChannelHandler1]
                                L --> S[ChannelHandler2]
                                M --> T[ChannelHandler1]
                                M --> U[ChannelHandler2]

                                style A fill:#e3f2fd,stroke:#42a5f5
                                style B fill:#bbdefb,stroke:#1e88e5
                                style C fill:#e8f5e9,stroke:#66bb6a
                                style D fill:#e8f5e9,stroke:#66bb6a
                                style E fill:#e8f5e9,stroke:#66bb6a
                                style F fill:#fff3e0,stroke:#ffa726
                                style G fill:#fff3e0,stroke:#ffa726
                                style H fill:#fff3e0,stroke:#ffa726
                                style I fill:#fff3e0,stroke:#ffa726
                                style J fill:#fce4ec,stroke:#f06292
                                style K fill:#fce4ec,stroke:#f06292
                                style L fill:#fce4ec,stroke:#f06292
                                style M fill:#fce4ec,stroke:#f06292
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-12">
        <div class="max-w-4xl mx-auto px-6 text-center">
            <div class="mb-4">
                <h3 class="text-xl font-bold text-white mb-2">技术小馆</h3>
                <p>深入解析技术原理，探索编程之美</p>
            </div>
            <div class="flex justify-center space-x-6">
                <a href="http://www.yuque.com/jtostring" class="hover:text-white transition duration-300">
                    <i class="fas fa-globe text-lg"></i>
                </a>
            </div>
            <div class="mt-6 text-sm">
                <p>© 2023 技术小馆. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script>
        // Initialize Mermaid
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: false,
                htmlLabels: true,
                curve: 'basis'
            }
        });

        // Copy button functionality
        document.querySelectorAll('.copy-btn').forEach(button => {
            button.addEventListener('click', function() {
                const codeBlock = this.parentNode.nextElementSibling;
                const range = document.createRange();
                range.selectNode(codeBlock);
                window.getSelection().removeAllRanges();
                window.getSelection().addRange(range);
                document.execCommand('copy');
                window.getSelection().removeAllRanges();
                
                // Show copied text
                const originalText = this.innerHTML;
                this.innerHTML = '<i class="fas fa-check"></i> 已复制';
                setTimeout(() => {
                    this.innerHTML = originalText;
                }, 2000);
            });
        });
    </script>
</body>
</html>
```